#ifndef LRU_CACHE_NODE_HPP
#define LRU_CACHE_NODE_HPP

#include <memory>

namespace CachePool
{
    // 前向声明
    template <typename Key, typename Value>
    class LruCache;

    template <typename Key, typename Value>
    class LruNode
    {
    private:
        Key key_;
        Value value_;

        size_t accessCount_; // 访问次数。LRU-K用到

        std::shared_ptr<LruNode<Key, Value>> prev_;
        std::shared_ptr<LruNode<Key, Value>> next_;

    public:
        LruNode(const Key &key, const Value &value)
            : key_(key), value_(value), accessCount_(1), prev_(nullptr), next_(nullptr)
        {
        }

        // 提供必要的访问器
        void setValue(const Value &value)
        {
            this->value_ = value;
        }

        void incrementAccessCount()
        {
            ++this->accessCount_;
        }

        Key getKey() const
        {
            return this->key_;
        }

        Value getValue() const
        {
            return this->value_;
        }

        size_t getAccessCount() const
        {
            return this->accessCount_;
        }

        friend class LruCache<Key, Value>; // 为了方便操作std::shared_ptr<>指向
    };
} // namespace CachePool

#endif // LRU_CACHE_NODE_HPP